<!DOCTYPE html>
<html lang="en">
<head>
    <title>添加</title>
    <link rel="stylesheet" href="${ctxPath!}/js/extend/formSelect/formSelects-v4.css"/>
    <%include("/WEB-INF/views/common/basejs.html"){}%>
    <script>
        //全局定义一次, 加载formSelects
        var formSelects;
        var pid='${resource.pid}';
        var icon='${resource.icon}';
        layui.config({
            base: '../js/extend/formSelect/' //此处路径请自行处理, 可以使用绝对路径
        }).extend({
            formSelects: 'formSelects-v4'
        }).use(['formSelects'],function(){
            formSelects=layui.formSelects;
        }).config({
            base: '../js/extend/iconSelect/'
        }).extend({
            iconPicker: 'iconPicker'
        }).use(['form','layer','jquery','iconPicker'],function(){
            var form = layui.form
                ,layer = layui.layer,
                $=layui.jquery,
                iconPicker=layui.iconPicker;
            var resourceListStr='${resourceListStr!}';
            var resourceList;
            if(resourceListStr){
                resourceList=JSON.parse(resourceListStr);
            }
           //初始化上级资源菜单树形结构
           formSelects.data('pid','server',{
               url:basePath+'/resource/showResourceTree',
               success:function(){
                   //禁用本身菜单
                   if(resourceList&&resourceList.length){
                       for(i in resourceList){
                           $('dd[lay-value="'+resourceList[i].id+'"]').addClass("xm-dis-disabled");
                       }
                   }
                   if(pid){
                       //设置默认值
                       formSelects.value('pid', [${resource.pid}]);
                   }
               }
           });
           //初始化图标选择器
            iconPicker.render({
                // 选择器，推荐使用input
                elem: '#iconPicker',
                // 数据类型：fontClass/unicode，推荐使用fontClass
                type: 'fontClass',
                search: false,
                // 是否开启搜索：true/false
                // 点击回调
                click: function (data) {
                    console.log(data);
                }
            });
            //设置已选中图标
            if(icon){
                iconPicker.checkIcon('iconPicker',icon);
            }
            //提交form监听表单
            form.on('submit(update)',function(data){
                  $.ajax({
                    url:basePath+'/resource/update',
                    type:'post',
                    data:data.field,
                    dataType:'json',
                    success:function(data){
                        if(data.code==0){
                            //更新父元素的表格
                            window.parent.query();
                            //添加成功之后关闭当前窗口
                            window.parent.closeEditPage();
                            window.parent.layer.msg(data.msg);
                        }
                    },
                    error:function(e){
                        window.parent.closeEditPage();
                        window.parent.layer.msg(e);
                    }
                });
                return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
            });
        });
    </script>
</head>
<body>
<form class="layui-form layui-form-pane" style="width:96%;margin:10px auto">
    <input type="hidden" name="id" value="${resource.id}">
    <input type="hidden" name="prePid" value="${resource.prePid}">
    <!--开始-->
    <!--资源名称-->
    <div class="layui-form-item">
        <label class="layui-form-label">资源名称</label>
        <div class="layui-input-block">
            <input name="resourceName" type="text" lay-verify="required"  autocomplete="off" placeholder="请输入资源名称" class="layui-input" value="${resource.resourceName}">
        </div>
    </div>
    <!--资源地址-->
    <div class="layui-form-item">
        <label class="layui-form-label">资源地址</label>
        <div class="layui-input-block">
            <input name="resourceUrl" type="text"   autocomplete="off" placeholder="请输入资源地址" class="layui-input" value="${resource.resourceUrl}">
        </div>
    </div>
    <!--权限标识符-->
    <div class="layui-form-item">
        <label class="layui-form-label">权限标识符</label>
        <div class="layui-input-block">
            <input name="resourceDesc" type="text"   autocomplete="off" placeholder="请输入权限标识符" class="layui-input" value="${resource.resourceDesc}">
        </div>
    </div>
    <!--上级资源-->
    <div class="layui-form-item">
        <label class="layui-form-label">上级资源</label>
        <div class="layui-input-block">
            <select name="pid" xm-select="pid" xm-select-radio xm-select-search>
                <option value="">请选择上级菜单</option>
            </select>
        </div>
    </div>
    <!--图标-->
    <div class="layui-form-item">
        <label class="layui-form-label">图标</label>
        <div class="layui-input-block">
            <input name="icon" type="text" id="iconPicker" lay-filter="iconPicker" class="layui-input" value="${resource.icon}">
        </div>
    </div>
    <!--类型-->
    <div class="layui-form-item">
        <label class="layui-form-label">类型</label>
        <div class="layui-input-block">
            <select name="type" lay-verify="required">
                <%
                if(resource.type==1){
                %>
                <option value="1" selected>菜单</option>
                <option value="2">按钮</option>
                <option value="3">页面</option>
                <%}
                else if(resource.type==2){
                %>
                <option value="1">菜单</option>
                <option value="2" selected>按钮</option>
                <option value="3">页面</option>
                <%}
                else if(resource.type==3){
                %>
                <option value="1">菜单</option>
                <option value="2" >按钮</option>
                <option value="3" selected>页面</option>
                <%}%>
            </select>
        </div>
    </div>
    <!--排序-->
    <div class="layui-form-item">
        <label class="layui-form-label">排序</label>
        <div class="layui-input-block">
            <input name="sort" type="number" value="${resource.sort}"  autocomplete="off" placeholder="请输入排序值" class="layui-input">
        </div>
    </div>
    <!--状态-->
    <div class="layui-form-item">
        <label class="layui-form-label">状态</label>
        <div class="layui-input-block">
            <%
            if(resource.status==1){
            %>
            <input type="radio" name="status" value="1" title="开启" checked>
            <input type="radio" name="status" value="2" title="禁用" >
            <%}
            else{
            %>
            <input type="radio" name="status" value="1" title="开启" >
            <input type="radio" name="status" value="2" title="禁用" checked>
            <%}%>
        </div>
    </div>
    <!--结束-->
    <div class="layui-form-item layui-hide">
        <button id="form-submit" class="layui-btn" lay-submit lay-filter="update">更新</button>
    </div>
</form>
</body>
</html>